package com.ruoyi.uni.service.impl;

import java.util.List;

import com.ruoyi.uni.domain.DcTypes;
import com.ruoyi.uni.mapper.DcTypesMapper;
import com.ruoyi.uni.service.IDcTypesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

/**
 * 点餐类型Service业务层处理
 * 
 * @author hx
 * @date 2024-04-14
 */
@Service
public class DcTypesServiceImpl implements IDcTypesService
{
    @Autowired
    private DcTypesMapper dcTypesMapper;

    @Override
    @Transactional
    public String move(Long id,int flag) {
        String ret="";
        DcTypes Myself  = dcTypesMapper.selectDcTypesById(id);
        if(Myself==null)
            return "数据错误";
        switch(flag){
            case 1:
                DcTypes Up = dcTypesMapper.selectMoveUp(Myself.getLocation());
                if(Up==null)
                    return "已经处于最上，无法上移";
                dcTypesMapper.updateLocationById(Myself.getId(), Up.getLocation());
                dcTypesMapper.updateLocationById(Up.getId(), Myself.getLocation());
                ret= "上移成功";
                break;
            case 2:
                DcTypes Down = dcTypesMapper.selectMoveDown(Myself.getLocation());
                if(Down==null)
                    return "已经处于最下，无法下移";
                dcTypesMapper.updateLocationById(Myself.getId(), Down.getLocation());
                dcTypesMapper.updateLocationById(Down.getId(), Myself.getLocation());
                ret="下移成功";
                break;
        }
        return ret;
    }

    /**
     * 查询点餐类型
     * 
     * @param id 点餐类型主键
     * @return 点餐类型
     */
    @Override
    public DcTypes selectDcTypesById(Long id)
    {
        return dcTypesMapper.selectDcTypesById(id);
    }

    /**
     * 查询点餐类型列表
     * 
     * @param dcTypes 点餐类型
     * @return 点餐类型
     */
    @Override
    public List<DcTypes> selectDcTypesList(DcTypes dcTypes)
    {
        return dcTypesMapper.selectDcTypesList(dcTypes);
    }

    /**
     * 新增点餐类型
     * 
     * @param dcTypes 点餐类型
     * @return 结果
     */
    @Override
    public int insertDcTypes(DcTypes dcTypes)
    {
        dcTypes.setLocation(dcTypesMapper.selectDcTypesCount()+1);
        return dcTypesMapper.insertDcTypes(dcTypes);
    }

    /**
     * 修改点餐类型
     * 
     * @param dcTypes 点餐类型
     * @return 结果
     */
    @Override
    public int updateDcTypes(DcTypes dcTypes)
    {
        return dcTypesMapper.updateDcTypes(dcTypes);
    }

    /**
     * 批量删除点餐类型
     * 
     * @param ids 需要删除的点餐类型主键
     * @return 结果
     */
    @Override
    public int deleteDcTypesByIds(Long[] ids)
    {
        return dcTypesMapper.deleteDcTypesByIds(ids);
    }

    /**
     * 删除点餐类型信息
     * 
     * @param id 点餐类型主键
     * @return 结果
     */
    @Override
    public int deleteDcTypesById(Long id)
    {
        return dcTypesMapper.deleteDcTypesById(id);
    }
}
